package com.kakaxi.mybilibili.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.bean.VideoCommentReplyItemBean;
import com.kakaxi.mybilibili.view.DividerItemDecoration;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * 视频评论列表适配器
 * Created by kakaxi on 16/11/23.
 */

public class VideoCommentRecyAdapter extends BaseQuickAdapter<VideoCommentReplyItemBean,
        BaseViewHolder> {


    public VideoCommentRecyAdapter(List<VideoCommentReplyItemBean> data) {
        super(R.layout.item_recy_video_comment, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, VideoCommentReplyItemBean
            videoCommentReplyBean) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm", Locale.getDefault());
        Date date = new Date(Long.valueOf(videoCommentReplyBean.getCtime() + "000"));
        baseViewHolder
                .setText(R.id.txt_video_comment_reply, videoCommentReplyBean.getCount() + "")
                .setText(R.id.txt_video_comment_like, videoCommentReplyBean.getLike() + "")
                .setText(R.id.txt_video_comment_floor, "#" + videoCommentReplyBean.getFloor())
                .setText(R.id.txt_video_comment_date, format.format(date))
                .setText(R.id.txt_video_comment_content, videoCommentReplyBean.getContent()
                        .getMessage())
                .setText(R.id.txt_video_comment_name, videoCommentReplyBean.getMember().getUname());
        Glide.with(mContext).load(videoCommentReplyBean.getMember().getAvatar()).crossFade().into
                ((ImageView) baseViewHolder.getView(R.id.civ_video_comment_face));
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        if (recyclerView.getLayoutManager() == null) {
            recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        }
        recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(),
                DividerItemDecoration.HORIZONTAL_LIST));
    }
}
